package com.mt.skyhoist.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;


import com.mt.skyhoist.util.bean.DaoMaster;
import com.mt.skyhoist.util.bean.DaoSession;
import com.mt.skyhoist.util.bean.DeviceModelDao;
import com.mt.skyhoist.util.bean.MixDatasModelDao;

import org.greenrobot.greendao.database.Database;

public class Repository {

    private DaoSession daoSession;

    private static Repository INSTANCE;

    public static Repository getInstance(){
        if(INSTANCE == null){
            INSTANCE = new Repository();
        }
        return INSTANCE;
    }

    public void init(Context context){
        SQLiteDatabase db;

        db = new DaoMaster.DevOpenHelper(context,"person.db", null).getWritableDatabase();

//        db = new RecoverOpenHelper(new CustomContext(context, "/sdcard/mysmartlift/"),
//                "lift.db", null).getWritableDatabase();

        daoSession = new DaoMaster(db).newSession();
    }

    public DeviceModelDao getDeviceModelDao(){
        return daoSession.getDeviceModelDao();
    }

    public MixDatasModelDao getMixDatasModelDao(){
        return daoSession.getMixDatasModelDao();
    }

    public class RecoverOpenHelper extends DaoMaster.DevOpenHelper {
        public RecoverOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
            super(context, name, factory);
        }

        public RecoverOpenHelper(Context context, String name) {
            super(context, name);
        }

        @Override
        public void onUpgrade(Database db, int oldVersion, int newVersion) {
        }
    }
}
